package cn.iotab.iotkit.transport.api.access.device;

import cn.iotab.iotkit.transport.api.access.handler.DeviceMessageHandler;
import cn.iotab.iotkit.transport.api.access.model.message.DeviceMessage;
import cn.iotab.iotkit.transport.api.access.model.message.DeviceMessageReply;
import com.google.common.util.concurrent.ListenableFuture;

public abstract class AbstractDeviceMessageHandler<M extends DeviceMessage> implements DeviceMessageHandler {

    @SuppressWarnings("all")
    @Override
    public ListenableFuture<DeviceMessageReply> process(DeviceMessage message) {
        M msg = null;
        try {
            msg = (M) message;
        } catch (ClassCastException e) {
            throw new IllegalStateException("message not match", e);
        }
        return doProcess(msg);
    }

    protected abstract ListenableFuture<DeviceMessageReply> doProcess(M message);


}
